The present invention is directed toward a system and method for editing source code templates in a target language utilizing a graphical user interface. More particularly, the present invention is directed to a system and method in which a programmer parameterizes target source code with contextual meta-data provided by the application domain. He determines the repetitive and nesting structures of the code which is visually clear, easy to maintain and fully consistent.
It is commonly said that object-oriented techniques help model the real world more closely than conventional techniques and it is mostly done using modeling tools. While building a complex system, software programmers and clients can easily establish their common vocabulary, which helps them refine system requirements effectively. Object-oriented techniques also help them build a system that is easily extensible, especially when frameworks are used.
Modeling tools are used by programmers or analysts to depict the business purpose of an application in a logical way that is abstracted from the xe2x80x9cphysical implementationxe2x80x9d of the specific programming language, operating system and the hardware that the application runs on.
One of the reasons that object-oriented programming is becoming more popular is that software reuse is becoming more important. Developing new systems is expensive, and maintaining them is even more expensive. A recent study by Wilma Osborne of the National Bureau of Standards suggests that 60 to 85 percent of the total cost of software is due to maintenance (Ware Meyers. Interview with Wilma Osborne. IEEE Software 5(3): 104-105, 1988).
Programmers traditionally use xe2x80x9ccut and pastexe2x80x9d techniques to facilitate the implementation of repetitive and near-repetitive methods. A kind of template is a block of target source code annotated where the change is needed, saved in a common location and reused by a programmer with some manual interventions. The programmer who created that block of target source code or another programmer can then re-use these lines by copying and pasting the appropriate lines into the code he is working on and making the appropriate changes for that particular usage. This method is error-prone and time-requiring since, in addition to copying the right lines of codes, sometimes repeatedly, the programmer has to replace all appropriate components"" names by their appropriate equivalents. This is called coding with annotated source code template.
Some generation software tools allow the programmer to use textual generation templates, which consist of parameterized lines of source code, to create new operations or components. These textual generation templates enable programmers to specify the selected components for which they want to generate code by using filter variables, as well as to define the complete specifications of the operation using target source code that is parameterized by context variables. Component and attribute filter variables are used by the code generator as selection criteria to filter information from the modeling tool and to populate its dynamic generation context. Context variables refer to a component or attribute property name that the code generator replaces with the actual property value associated with the current component or attribute found in its dynamic context.
These code generators are used to deliver generation-time control and customization for integrating frameworks with components developed using today""s modeling tools and programming languages. Textual generation templates are created with programmer""s instructions that are given using a rigorous syntax and are used by the source code generator to replace any context variable in the provided parameterized source code. For example, a line of code could be: xe2x80x9cpersistenceSchema=new PersistenceSchema(xe2x80x9c%001xe2x80x9d); with (andclass name)xe2x80x9d, in which xe2x80x9c%001xe2x80x9d is a parametric symbol representing where the value of the context variable would be put by the generator, for example, the context variable xe2x80x9c less than class name greater than xe2x80x9d. The programmer has to create textual generation templates using these symbols. A mental list of such symbols must be built up in order for the programmer to stay consistent in naming the components, especially when there is more than one parametric symbol from %001 up to %999 that needs to be respectively associated with a context variable. A parametric symbol can appear more than once in the parameterized source code since it is always associated with the same context variable. Such symbols are not user-friendly in the sense that they do not enable the programmer to type code, as he would normally do in a non-parameterized form. In addition, these symbols have to be defined within the lines of codes to ensure proper interpretation by the generator. In the previous example, the instruction xe2x80x9cwith (andclass name)xe2x80x9d has to be added in order to instruct the generator that the parametric symbol xe2x80x9c%1xe2x80x9d would be replaced by the current value of the context variable associated with the current class found in the dynamic context of the generator. Also, when certain portions of the code have to be repeated more than once for attributes of a component that address the selection criteria provided by filter variables, an instruction of the kind xe2x80x9crepeatForEach andattribute private instance using (andattribute name; andattribute attributeClassName;xe2x80x9d would have to be included to ensure the near-repetitive operation. The code generator, in this case, will take the templates and transform then into source code using a model declaration for the system and filter variables that are defined in order to specify which templates are used for which components.
Instead of using such a syntax relying on keywords (i.e. %001) and definitions of such keywords (i.e. repeatForEach . . . using . . . or with . . . ), a programmer could decide to concatenate the parameterized code with the result of an instruction performed by an algorithm implemented in a given programming language. For example, like is taught in U.S. Pat. No. 5,675,801 to Lindsey, the software would solve the expression in parameterized form with the result of another operation. More specifically, in an example of the declaration source code template in the C language for data-oriented object known as the NumericDataItemObject and representing the C variable called xe2x80x9cIdNumberxe2x80x9d, an instruction of the kind xe2x80x9cint  less than self VarName greater than ;xe2x80x9d could be used, in which xe2x80x9cintxe2x80x9d and xe2x80x9c;xe2x80x9d are the source code fragment portion of this source code template and the directive for the generator is xe2x80x9c less than self VarName greater than xe2x80x9d. In this example, the xe2x80x9c less than xe2x80x9d and xe2x80x9c greater than xe2x80x9d are arbitrary delineators indicating the beginning and the end of a generator directive. In this case, the object identifier is the token xe2x80x9cselfxe2x80x9d, which refers to the object being asked to generate itself, namely xe2x80x9cIdNumberxe2x80x9d, its variable name. The message identifier is the token xe2x80x9cvarNamexe2x80x9d which will be the message sent to the object xe2x80x9cselfxe2x80x9d. This message tells the object xe2x80x9cselfxe2x80x9d to return the string representing itself when used in a variable declaration. In this example for Lindsey, the NumericDataItemObject, whose name is xe2x80x9cIdNumberxe2x80x9d, will return the string xe2x80x9cidNumberxe2x80x9d. The resulting target language source code fragment is xe2x80x9cint idNumber;xe2x80x9d, which is a C language source code fragment.
The use of colors and other display artifacts have been used in source code editors to increase the understanding of the procedural flow of an algorithm but never used to describe the structure of the information provided, such as repetitive and/or nested Context Blocks. For example, an If-then-else statement using different colors for its condition expression, its true-expression and its false-expression that have to be executed based on the result of the conditional expression. Display artifacts have never been used to illustrate the fact that the same if-then-else expression is repeated within a given component algorithm for every attribute meeting a set of selection criteria.
Accordingly, it is an object of the present invention to provide an editor that would enable programmers to create templates that are visually clear and efficient.
Another object of the present invention is to provide an editor in which repetitive and nested code is clearly identified.
Another object of the present invention is to provide an editor for creating source code templates which requires a minimum of programmer intervention to obtain the desired templates.
Yet another object of the present invention is to provide a template editor that meets the needs for editing the template source code, which can be used in all kinds of environments such as web-based servers, framework environments, code generation or else.
Another object of the present invention is to use an editor to generate script templates.
To achieve the foregoing objects in a computing environment, and in accordance with the purpose of the invention as broadly described herein, a system is provided for editing templates of component based source code. This system comprises a context editor for entering source code and, when parameterized, context variables representing the component or attribute property name that will be replaced by the generator with its actual property value at generation time. The source code is in fact captured into context blocks that can be nested among each other. They can represent a constant, conditional or repetitive context block in which case condition expressions are provided to determine if the context block is generated and how many times it will occur.
A second method provides for creating a source code template, contextually capturing control information, and representing context variables and context blocks using display effects. These effects comprise, among others, color, special fonts, modified cursor behaviors or even sound effects.
In a general aspect of the invention, two unique preferred embodiments are provided and are both related to the manipulation of hierarchically structured control information. The first process allows the efficient creation, modification and visualization of the control information for humans. The second provides a deterministic transformation of this control information into a machine-understandable format.
The first process provides a context sensitive editor to create, modify and display hierarchically structured control information. The editor presents action choices appropriate to the immediately current context, thereby simplifying the manipulation protocol of the user. Because the editor understands the relationships and multiplicity between the contexts, its graphical user interface represents the repetition and conditionality of the blocks without resorting to a scripting language. The editor displays the control information according to the presentation rules of the associated context. The presentation clearly differentiates between the bulk text, the structure in which the text resides, and parameterized elements. The editor effectively manipulates what is meta control information in a way that displays it as information.
According to a preferred embodiment of the present invention, there is provided a method and a system for displaying hierarchically structured data. The method and system comprise specifying control information concerning parametric elements of the hierarchically structured data, editing a template for the hierarchically structured data and specifying non-parametric elements of the data, specifying a context parameter as a parametric element of the data, specifying a filtering option for at least one block of the hierarchically structured data comprising at least one non-parametric element and one parametric element, associating a display characteristic with each the filtering option, displaying the hierarchically structured data identified using the display characteristic.
The second process provides a method to systematically transform the control information into a machine-understandable format.
According to another preferred embodiment of the present invention, there is provided a method for transforming hierarchically structured data into code generator script data. The method comprises specifying control information concerning parametric elements of the hierarchically structured data, editing a template for the hierarchically structured data and specifying non-parametric elements of the data, specifying a context parameter as a parametric element of the data, specifying a filtering option for at least one block of the hierarchically structured data comprising at least one non-parametric element and one parametric element, generating code generator script data using the control information, the template, the filtering option and the context parameter for a desired source code language.